<template>
	<!-- 登录的相关操作 -->
	<view class="login">
		
		<input type="number" v-model="phone" placeholder="请输入手机号码" maxlength="11" confirm-type="done"></input>
		<input type="text" v-model="pass" :password="true" placeholder="请输入密码" maxlength="50" bindconfirm="toLogin" confirm-type="done"></input>
		
	</view>
</template>

<script>
	export default{
		data() {
			return {
				phone: '',
				pass: ''
			}
		},
		methods: {
			toLogin() {
				if(this.loginFlag){
					this.loginFlag = false;
				}else{
					return;
				}
				let phone = this.phone.replace(/(^\s*)|(\s*$)/g, "");
				let pass = this.pass.replace(/(^\s*)|(\s*$)/g, "")
				
				if (!phone) {
					uni.showToast({
						title: '请输入手机号码',
						mask: true,
						icon:'none'
					})
					this.loginFlag = true;
				    return;
				}
			
				let isPhone = this.isPoneAvailable(phone)
				
				if (!isPhone) {
					uni.showToast({
						title: '请输入有效的手机号码',
						mask: true,
						icon: 'none'
					})
					this.loginFlag = true;
				    return;
				}
			
				if (!pass) {
					uni.showToast({
						title: '请输入密码',
						mask: true,
						icon: 'none'
					})
					this.loginFlag = true;
				    return;
				}
			},
			
			/**
			 * 获取当前WiFi信号强度
			 */
			checkWifiSignal() {
				console.log('获取当前WiFi信号强度  ')
				// #ifdef APP-PLUS
				
			     let Signal = null;  
			     let Context = plus.android.importClass("android.content.Context");  
			     let WifiManager = plus.android.importClass("android.net.wifi.WifiManager");  
			     let Main = plus.android.runtimeMainActivity();  
			     WifiManager = Main.getSystemService(Context.WIFI_SERVICE);  
			     let WifiInfo = plus.android.importClass("android.net.wifi.WifiInfo");  
			     WifiInfo = WifiManager.getConnectionInfo();  
			     let wifi = WifiInfo.getRssi();  
			 			
			     if (wifi > -50 && wifi < 0) { //最强  
			         Signal = "最强";  
			     } else if (wifi > -70 && wifi < -50) { //较强  
			         Signal = "较强";  
			     } else if (wifi > -80 && wifi < -70) { //较弱  
			         Signal = "较弱";  
			     } else if (wifi > -100 && wifi < -80) { //微弱  
			         Signal = "微弱";  
			     }  
				console.log('WiFi强弱', Signal, wifi)
				if(wifi < -70) {
					uni.showModal({
						title: '网络信号不好',
						content: '当前网络信号不好，请到网络好的地方登录。',
						showCancel: false
					})
				}
			     return Signal; 
				  
				 // #endif 
			 },
			 
			/**
			 * 获取用户本地存储的密码
			 */
			getUserLogin() {
				let that = this;
				uni.getStorage({
					key: 'userLogin',
					success(res){
						// console.log('获取用户本地存储的密码', res)
						let data = res.data;
						that.phone = data.phone;
						that.pass = data.pass;
						that.isSame = data.phone;
					},
					fail(res) {
						// console.log('获取用户本地存储的密码 err', res )
						that.phone = '';
						that.pass = '';
						that.isSame = '';
					}
				})
			},
			
			/**
			 * 判断是否为手机号
			 * @param {Object} phone
			 */
			isPoneAvailable(phone) {
				let myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
				if (!myreg.test(phone)) {
					return false;
				} else {
					return true;
				}
			}
		}
	}
</script>

<style lang="scss">
	
</style>
